<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body>
	<div class="layui-fluid">
		<form class="layui-form" action="" lay-filter="menu-add-form">
			<hr class="layui-bg-gray">
			<input type="hidden" th:value="${menuId}" name="menuId">
			<!-- 下拉选择框 -->
			<select name="parentId" lay-verify="required|number">
				<option value="">请选择一个目录</option>
				<option th:each="d:${dir}" th:value="${d.menuId}" th:text="${d.name}"></option>
			</select>
			<table class="layui-table">
				<thead>
					<tr>
						<th>菜单名称</th>
						<th>权限标识</th>
						<th>菜单url</th>
						<th>图标</th>
						<th>类型</th>
					</tr>
				</thead>
				<tbody>
					<tr th:each="menu:${menus}">
						<td th:text="${menu.name}"></td>
						<td th:text="${menu.perms}"></td>
						<td th:text="${menu.url}"></td>
						<td>
							<i th:class="${menu.icon}"></i>
						</td>
						<td th:switch="${menu.type}">
							<p th:case="0">
								<span class="layui-badge layui-bg-blue">目录</span>
							</p>
							<p th:case="1">
								<span class="layui-badge layui-bg-green">菜单</span>
							</p>
							<p th:case="2">
								<span class="layui-badge layui-bg-gray">按钮</span>
							</p>
						</td>
					</tr>
				</tbody>
			</table>
			<button class="layui-btn" lay-submit="" lay-filter="menu-add">立即提交</button>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<script>
		layui.use([ 'form' ], function() {
			var form = layui.form, layer = layui.layer;
			var $ = layui.jquery;
			//监听提交

			form.on('submit(menu-add)', function(data) {
				//提交数据data.field
				$.ajax({
					cache : true,
					type : "POST",
					url : "/sys/menu/adminAdd",
					data : data.field,
					async : false,
					error : function(request) {
						layer.alert("Connection error");
					},
					success : function(r) {
						if (r.retCode == '0000') {
							parent.layer.msg("保存成功");
							parent.location.reload(); // 父页面刷新
							var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
							parent.layer.close(index);
						} else {
							layer.alert(r.retMsg)
						}
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>